Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep whitespace in extract to code behind #9262

Merged
merged 10 commits into from
Sep 12, 2023

Conversation

davidwengier
Copy link
Contributor

Fixes #8750

The main fix here is to not use NormalizeWhitespace, but the formatter instead, as the former clobbers too much of the users code. Commit-at-a-time is probably the way to go, to see how the test output changes (or doesn't 😛)

Calling NormalizeWhitespace is the lazy way to not have to worry about trivia when using SyntaxFactory, but it also destroys any formatting the user might have done. Better to use the actual formatter to fix indentation and things, and just generate the code as a string.

Using syntax factory wasn't really helping too much.
Just to make sure the formatter is doing the right thing
The invalid C# code annoyed me :P
@davidwengier davidwengier requested a review from a team as a code owner September 10, 2023 23:43
Turns out this test was invalid, and this behaviour is not possible to do on our side. The good news is the old code was just as wrong, and I have a better solution in the works :)
Comment on lines 187 to 188
.GetDocumentIntermediateNode()
.FindDescendantNodes<UsingDirectiveIntermediateNode>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

@davidwengier davidwengier merged commit 25f8cf1 into dotnet:main Sep 12, 2023
12 checks passed
@ghost ghost added this to the Next milestone Sep 12, 2023
@davidwengier davidwengier deleted the BetterExtractToCodeBehind branch September 12, 2023 22:26
davidwengier added a commit that referenced this pull request Sep 14, 2023
Fixes #4330
Fixes #8766
Includes #9262 so just review from
8a2b8af
onwards

Goes with dotnet/roslyn#69878 and
dotnet/vscode-csharp#6329

I logged #9264 to follow up with a
better test, though strictly speaking the one I've added id exhaustive
:)

Behaviour of Extract to Code Behind before this change. Note the many
using statements and block scoped namespace.

![ExtractToCodeBehindBefore](https://github.com/dotnet/razor/assets/754264/10ac5595-b3b2-44c2-a1a7-66664d3c8f1b)

Behaviour after this change. Note the file scoped namespace, and file
header.

![ExtractToCodeBehindAfter](https://github.com/dotnet/razor/assets/754264/65160715-bc98-4336-b19d-37f9b14adf94)

The squiggle on `NavigationManager` is due to an `.editorconfig` rule I
have on in that project, requiring `this.` qualification, so is
unrelated.
@Cosifne Cosifne modified the milestones: Next, 17.8 P3 Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract to code behind loses trivia/whitespace
3 participants